var app =new Vue({
    el:"#container",
    data:{
        user:{},
        oldPassword:"",
        password:"",
        affirm:"",
    },
    mounted(){
        this.userInfo();
    },
    methods:{
        userInfo(){
            axios({
                url:"yly-api/admin/queryEmpAccountByToken",
                method:"get",
                headers:{"token":localStorage.token,"url":window.location.pathname}
            }).then(function (res) {
               console.log(res);
                app.user=res.data;
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("权限不足，无法访问!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        pwd(){
            let data=new URLSearchParams();
            data.append("password",app.oldPassword);
            axios({
                url:"yly-api/admin/judgePwd",
                data:data,
                headers:{"token":localStorage.token,"url":window.location.pathname},
                method: "post"
            }).then(function (res){
                if(res.data=="success"){
                    $(".error").html("密码输入正确！");
                }else {
                    $(".error").html("密码错误，请重新输入！");
                    app.oldPassword="";
                }
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("权限不足，无法访问!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        updateUser(){
            let data=new URLSearchParams();
            data.append("userName",app.user.userName);
            data.append("address",app.user.address);
            data.append("phone",app.user.phone);
            data.append("keyContactsphone",app.user.keyContactsphone);
            data.append("identityCode",app.user.identityCode);
            data.append("id",app.user.id);
            data.append("jobNumber",app.user.jobNumber);

            axios({
                url:"yly-api/admin/updateEmpAccount",
                method: "post",
                headers:{"token":localStorage.token,"url":window.location.pathname},
                data:data
            }).then(function (res) {
                console.log(res.data);
                if (res.data.code==200){
                    if (res.data.data==true){
                        alert("修改成功！");
                    }else {
                        alert("修改失败，请联系管理员！");
                    }

                }else {
                    location.href="500.html";
                }
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("权限不足，无法访问!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },
        updateImg(event){
            console.log(event.target.files[0]);
            let data=new FormData();
            data.append("file",event.target.files[0]);
            axios({
                url:"yly-api/admin/uploading",
                method: "post",
                headers:{"token":localStorage.token,"url":window.location.pathname},
                data:data
            }).then(function (res) {
                console.log(res.data);
                if (res.data=="success"){
                    alert("上传成功！");
                    location.href="";
                }else {
                    alert("上传失败,请联系管理员！");
                }
            }).catch(function (error) {
                console.log(error.response.status);
                if (error.response.status==401){
                    alert("权限不足，无法访问!");
                    location.href="login.html";
                }else if (error.response.status==403){
                    alert("用户已过期，请重新登录！");
                    localStorage.token=null;
                    location.href="login.html";
                }
            })
        },

    }
})